<template>
  <div class="page-register">
    <div class="header">
      <header>
        <a href="#" class="site-logo"></a>
        <div class="login">
          <span>已有美团账号？</span>
          <router-link :to="{ name: 'login' }">登录</router-link>
        </div>
      </header>
    </div>
    <div class="content">
      <el-form
        :model="registerForm"
        status-icon
        :rules="rules"
        ref="registerForm"
        label-width="100px"
        class="demo-registerForm"
      >
        <el-form-item label="用户名" prop="userName">
          <el-input
            type="text"
            v-model="registerForm.userName"
            autocomplete="off"
          ></el-input>
        </el-form-item>
        <el-form-item label="短信动态码" prop="note">
          <el-input
            type="text"
            v-model="registerForm.note"
            autocomplete="off"
          ></el-input>
        </el-form-item>

        <el-form-item label="密码" prop="password">
          <el-input
            type="password"
            v-model="registerForm.password"
            autocomplete="off" @input="input"
          ></el-input>
        </el-form-item>
        <div class="pw-strength">
          <div :class="['bar', strengthClass]"></div>
          <div class="letter">
            <span>弱</span>
            <span>中</span>
            <span>强</span>
          </div>
        </div>
        <el-form-item label="确认密码" prop="rePassword">
          <el-input
            type="password"
            v-model="registerForm.rePassword"
            autocomplete="off"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('registerForm')"
          style="width:178px;height:35px;padding:7px 20px 6px 20px;margin-top:-10px;background-color:#2db3a6;"
            >同意以下协议并注册</el-button
          >
        </el-form-item>
        <p style="font-size: 13px;color: #FE8C00;margin-left:110px">

          <a href="#" ><span>《美团点评用户服务协议》</span></a>
          <a href=""><span>《美团点评隐私政策》</span></a>
        </p>
      </el-form>
    </div>
    <footer></footer>
  </div>
</template>

<script>
export default {
  data() {
        var  validateNote =(rule, value, callback) =>{
        if (value === ""){
        callback(new Error("请输入验证码"));
        }
        callback();            
        
        }
    var  validateUser =(rule, value, callback) =>{
        if (value === ""){
        callback(new Error("请输入用户名"));
        }else if(value.length<4 || value.length>16){
        callback(new Error("用户名必须为4-16位的数字下划线组成"));
        }else{
        callback();            
        }
    }
    var validatePass = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入密码"));
      } else {
        if (this.registerForm.rePassword !== "") {
          this.$refs.registerForm.validateField("rePassword");
        }
        callback();
      }
    };
    var validatePass2 = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请再次输入密码"));
      } else if (value !== this.registerForm.password) {
        callback(new Error("两次输入密码不一致!"));
      } else {
        callback();
      }
    };

    return {
      registerForm: {
        userName: "",
        passwprd: "" ,
        rePassword:'',
        note:''
      },
      strengthClass: "",
      rules: {
        note:[{validator:validateNote,trigger:'blur'}],
        userName:[{validator:validateUser,trigger:'blur'}],
        password: [{ validator: validatePass, trigger: "blur" }],
        rePassword: [{ validator: validatePass2, trigger: "blur" }],
      }
    };
  },
  methods:{
      submitForm(){
          console.log(this.password,this.rePassword)
      },
      input(){
          if(this.password.length>20){
              this.strengthClass='strong'
          }else if(this.password.length>15){
            this.strengthClass='normal'
          }else{
              this.strengthClass='week'
          }
      }
  }
};
</script>

<style lang="scss">
@import "@/assets/css/register/index.scss";
</style>
